#include <iostream>
#include <array>
#include <set>
#include <algorithm>

using namespace std;

static bool contain(const array<int, 6>&a, int e) {
    if (e == 6 || e == 9)
        return find(a.begin(), a.end(), 6) != a.end() || find(a.begin(), a.end(), 9) != a.end();
    else 
        return find(a.begin(), a.end(), e) != a.end();
}

static bool valid(const array<int, 6>&a0, const array<int, 6>&a1) {
    constexpr array<pair<int, int>, 9> p {{{0, 1}, {0, 4}, {0, 9}, {1, 6}, {2, 5}, {3, 6}, {4, 9}, {6, 4}, {8, 1}}};
    for (auto& e: p) {
        if (!(contain(a0, e.first) && contain(a1, e.second) || contain(a0, e.second) && contain(a1, e.first)))
            return false;
    }
    return true;
}

static set<array<int, 6>> generate_set() {
    set<array<int, 6>> s;
    constexpr array<int, 10> arr {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    for (int a = 0; a < arr.size(); ++a) {
        for (int b = a + 1; b < arr.size(); ++b) {
            for (int c = b + 1; c < arr.size(); ++c) {
                for (int d = c + 1; d < arr.size(); ++d) {
                    for (int e = d + 1; e < arr.size(); ++e) {
                        for (int f = e + 1; f < arr.size(); ++f) {
                            s.insert({arr[a], arr[b], arr[c], arr[d], arr[e], arr[f]});
                        }
                    }
                }
            }
        }
    }
    return s;
}

static bool array_compare(const array<int, 6>& a, const array<int, 6>& b) {
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] < b[i])
            return true;
        else if (a[i] > b[i])
            return false;
    }
    return false;
}

int main() {
    set<pair<array<int, 6>, array<int, 6>>> s;
    auto s0 = generate_set();
    auto s1 = generate_set();
    for (auto& a0: s0) {
        for (auto& a1 : s1) {
            if (valid(a0, a1))
                array_compare(a0, a1) ? s.insert({a0, a1}) : s.insert({a1, a0});
        }
    }
    cout << s.size() << endl;
}   // 1217